package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadTest {


    public static void main(String[] args) {

        test1();
        test2();

        int num = 5; // 线程池中线程的数量
        ExecutorService executorService = Executors.newFixedThreadPool(num); // 创建线程池对象

        Runnable taskOne = new Runnable() { // 创建Runnable任务
            @Override
            public void run() {
                System.out.println("线程任务1正在执行...");
            }
        };

        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable);

        executorService.execute(thread);
        executorService.shutdown();


    }

    public static void test1(){
        MyThread myThread = new MyThread();
        myThread.start();
    }

    public static void test2(){
        MyRunnable myRunnable = new MyRunnable();
        Thread thread = new Thread(myRunnable);
        thread.start();
    }

}
